//
//  BlindingDeviceView.m
//  iiecg
//
//  Created by 123456 on 2017/11/17.
//  Copyright © 2017年 Boundary Technology. All rights reserved.
//

#import "BlindingDeviceView.h"
#import "Masonry.h"

@interface BlindingDeviceView ()

@property (nonatomic,strong)UIImageView *circle;

@end

@implementation BlindingDeviceView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void)rotationanimation
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 99999;
    [self.circle.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}


-(void)stoprotationanimation
{
    [self.circle.layer removeAnimationForKey:@"rotationAnimation"];
}


-(void)setupUI
{
    self.backgroundColor = ECG_COLOR_WHITE;
    
    UILabel *blindingLab = [[UILabel alloc] init];
    blindingLab.textColor = [UIColor lightGrayColor];
    blindingLab.textAlignment = NSTextAlignmentCenter;
    blindingLab.userInteractionEnabled = YES;
    blindingLab.hidden = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(notranslation)];
    [blindingLab addGestureRecognizer:tap];
//    blindingLab.text = @"暂不绑定 >";
    blindingLab.font = FONT_LABEL;
    [self addSubview:blindingLab];
    [blindingLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self).with.offset(-32);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
        make.bottom.equalTo(self.mas_bottom).with.offset(- 79);
    }];
    
    UIView *containerView = [[UIView alloc] init];
    containerView.backgroundColor = ECG_COLOR_WHITE;
    [self addSubview:containerView];
    [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.right.equalTo(self);
        make.bottom.equalTo(blindingLab.mas_top);
    }];
    //circle
    UIImageView *circle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ecg_bind_circle"]];
    self.circle = circle;
    [containerView addSubview:circle];
    circle.userInteractionEnabled = YES;
    [circle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(containerView);
        make.top.mas_equalTo(100);
        make.width.and.height.mas_offset(120);
    }];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ecg_bleicon"]];
    [containerView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(circle);
        make.width.and.height.mas_equalTo(97);
    }];
    
    UILabel *searchLab = [[UILabel alloc] init];
    searchLab.text = INTERNATIONAL(@"string_scanning_device");
    searchLab.textColor = COLOR_BLACK_6F6F6F;
    searchLab.font = FONT_BASIC;
    searchLab.textAlignment = NSTextAlignmentCenter;
    [containerView addSubview:searchLab];
    [searchLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.equalTo(imageView.mas_bottom).with.offset(40);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *descLab = [[UILabel alloc] init];
    descLab.textColor = [UIColor lightGrayColor];
    descLab.textAlignment = NSTextAlignmentCenter;
    descLab.text = INTERNATIONAL(@"fw_click_device");
    descLab.font = FONT_LABEL;
    descLab.numberOfLines = 0;
    [containerView addSubview:descLab];
    [descLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(searchLab);
        make.top.equalTo(searchLab.mas_bottom).with.offset(10);
        make.height.mas_equalTo(36);
    }];
}

-(void)notranslation
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(callbacknoBlinding)])
    {
        [self.delegate callbacknoBlinding];
    }
}

@end

